﻿import { PagedRequestDto } from "@shared/component-base";
import { UploadFileDto } from "@shared/model/uploadfiledto";
export interface IProductDto {
  id:number;
  name:string;
  categoryId:number;
  categoryName:string;
  imageUrl:string;
  price:number;
  oldPrice:number;
  productCost:number;
  sku:string;
  content:string;
  stockQuantity:number;
  soldQuantity:number;
  keywords:string;
  weight:number;
  length:number;
  width:number;
  height:number;
}

export class ProductDto implements IProductDto {
  id:number;
  name:string;
  categoryId:number;
  categoryName:string;
  imageUrl:string;
  price:number;
  oldPrice:number;
  productCost:number;
  sku:string;
  content:string;
  stockQuantity:number;
  soldQuantity:number;
  keywords:string;
  weight:number;
  length:number;
  width:number;
  height:number;

  constructor(data?: IProductDto) {
    if (data) {
      for (var property in data) {
        if (data.hasOwnProperty(property))
          (<any>this)[property] = (<any>data)[property];
      }
    }
  }

  init(data?: any) {
    if (data) {
      this.id = data["id"];
      this.name = data["name"];
      this.categoryId = data["categoryId"];
      this.price = data["price"];
      this.oldPrice = data["oldPrice"];
      this.productCost = data["productCost"];
      this.categoryName = data["categoryName"];
      this.imageUrl = data["imageUrl"];
      this.sku = data["sku"];
      this.content = data["content"];
      this.stockQuantity = data["stockQuantity"];
      this.soldQuantity = data["soldQuantity"];
      this.keywords = data["keywords"];
      this.weight = data["weight"];
      this.length = data["length"];
      this.width = data["width"];
      this.height = data["height"];
      
    }
  }

  static fromJS(data: any): ProductDto {
    data = typeof data === 'object' ? data : {};
    let result = new ProductDto();
    result.init(data);
    return result;
  }

  toJSON(data?: any) {
    data = typeof data === 'object' ? data : {};
      data["id"]=this.id;
      data["name"]=this.name;
      data["categoryId"]=this.categoryId;
      data["price"]=this.price;
      data["oldPrice"]=this.oldPrice;
      data["productCost"]=this.productCost;
      data["categoryName"]=this.categoryName;
      data["imageUrl"]=this.imageUrl;
      data["sku"]=this.sku;
      data["content"]=this.content;
      data["stockQuantity"]=this.stockQuantity;
      data["soldQuantity"]=this.soldQuantity;
      data["keywords"]=this.keywords;
      data["weight"]=this.weight;
      data["length"]=this.length;
      data["width"]=this.width;
      data["height"]=this.height;

    return data;
  }

  clone() {
    const json = this.toJSON();
    let result = new ProductDto();
    result.init(json);
    return result;
  }
}

export class ProductListQueryDto extends PagedRequestDto {
  phone: string;
  keywords: string;

  init(data?: any) {
    if (data) {
      this.pageIndex = data["pageIndex"];
      this.pageSize = data["pageSize"];
      this.sortField = data["sortField"];
      this.sortOrder = data["sortOrder"];
      this.keywords = data["keywords"];
    }
  }

  toJSON(data?: any) {
    data = typeof data === 'object' ? data : {};
    data["pageIndex"] = this.pageIndex;
    data["pageSize"] = this.pageSize;
    data["sortField"] = this.sortField;
    data["sortOrder"] = this.sortOrder;
    data["keywords"] = this.keywords;
    return data;
  }
}

export interface IProductEditDto {
  id:number;
  name:string;
  categoryId:string;
  price:number;
  oldPrice:number;
  productCost:number;
  sku:string;
  content:string;
  stockQuantity:number;
  soldQuantity:number;
  keywords:string;
  weight:number;
  length:number;
  width:number;
  height:number;
  imageList: UploadFileDto[];
}

export class ProductEditDto implements IProductEditDto {
  id:number;
  name:string;
  categoryId:string;
  price:number;
  oldPrice:number;
  productCost:number;
  sku:string;
  content:string;
  stockQuantity:number;
  soldQuantity:number;
  keywords:string;
  weight:number;
  length:number;
  width:number;
  height:number;
  imageList: UploadFileDto[];

  constructor(data?: IProductEditDto) {
    if (data) {
      for (var property in data) {
        if (data.hasOwnProperty(property))
          (<any>this)[property] = (<any>data)[property];
      }
    }
  }

  init(data?: any) {
    if (data) {
      this.id = data["id"];
      this.name = data["name"];
      this.categoryId = data["categoryId"]+"";
      this.price = data["price"];
      this.oldPrice = data["oldPrice"];
      this.productCost = data["productCost"];
      this.sku = data["sku"];
      this.content = data["content"];
      this.stockQuantity = data["stockQuantity"];
      this.soldQuantity = data["soldQuantity"];
      this.keywords = data["keywords"];
      this.weight = data["weight"];
      this.length = data["length"];
      this.width = data["width"];
      this.height = data["height"];
      this.imageList = data["imageList"];
      
    }
  }

  static fromJS(data: any): ProductEditDto {
    data = typeof data === 'object' ? data : {};
    let result = new ProductEditDto();
    result.init(data);
    return result;
  }

  toJSON(data?: any) {
    data = typeof data === 'object' ? data : {};
      data["id"]=this.id;
      data["name"]=this.name;
      data["categoryId"]=this.categoryId;
      data["price"]=this.price;
      data["oldPrice"]=this.oldPrice;
      data["productCost"]=this.productCost;
      data["sku"]=this.sku;
      data["content"]=this.content;
      data["stockQuantity"]=this.stockQuantity;
      data["soldQuantity"]=this.soldQuantity;
      data["keywords"]=this.keywords;
      data["weight"]=this.weight;
      data["length"]=this.length;
      data["width"]=this.width;
      data["height"]=this.height;
      data["imageList"]=this.imageList;
      

    return data;
  }

  clone() {
    const json = this.toJSON();
    let result = new ProductEditDto();
    result.init(json);
    return result;
  }
}


